class OrderedSet(object):
  def __init__(self):
    self._items = {}
    self._keys = []
  
  def __iter__(self):
    for key in self._keys:
      yield self._items[key]

  def __getitem__(self, n):
    return self._items[self._keys[n]]

  def __delitem__(self, n):
    del(self._items[self._keys[n]])
    del(self._keys[n])

  def __len__(self):
    return len(self._keys)

  def __str__(self):
    return str(self._keys)

  def add(self, item):
    if item in self._items:
      self._keys.remove(item)
    else:
      self._items[item] = item
    self._keys.append(item)
